/**
 * Copyright (c) 2020-2024, huli.com
 * All rights reserved.
 */
package com.xiaohujr.xuexue.mytest;

import com.alibaba.fastjson.JSON;

/**
 * @author Xue Xue (xuexue1@huli.com)
 * @version 1.0
 * @since 2021/2/4
 */
public class TestNodeReverse {


    private class ListNode{
        int val;
        ListNode next;

        public ListNode(int val) {
            this.val = val;
        }

        public int getVal() {
            return val;
        }

        public void setVal(int val) {
            this.val = val;
        }

        public ListNode getNext() {
            return next;
        }

        public void setNext(ListNode next) {
            this.next = next;
        }
    }
    public static ListNode TestNodeReverse(ListNode node){
        ListNode preNode = null;
        ListNode curNode = node;
        while (curNode!=null){
            ListNode nextNode = curNode.next;
            curNode.next = preNode;
            preNode = curNode;
            curNode = nextNode;
        }
        return preNode;
    }

    public static void main(String[] args) {
        TestNodeReverse.ListNode a = new TestNodeReverse().new ListNode(1);
        TestNodeReverse.ListNode b =  new TestNodeReverse().new ListNode(2);
        TestNodeReverse.ListNode c =  new TestNodeReverse().new ListNode(3);
        TestNodeReverse.ListNode d =  new TestNodeReverse().new ListNode(4);
        a.next = b;
        b.next = c;
        c.next = d;
        System.out.println(JSON.toJSONString(TestNodeReverse.TestNodeReverse(a)));
    }

}
